﻿using Digitalmes.Domain;
using Digitalmes.Domain.Mes;
using Digitalmes.Scada.Models;
using Digitalmes.Sugar;

namespace Digitalmes.Scada.Services.Impl;

internal sealed class TakePartInService : ITakePartInService, ITransientDependency
{
    private readonly SugarRepository<ProdTransSn> _transSnRepo;

    public TakePartInService(SugarRepository<ProdTransSn> transSnRepo)
    {
        _transSnRepo = transSnRepo;
    }

    public async Task<HandleResult> TakePartInAsync(TakePartInInput input)
    {
        // 前提是检测产品是否是返修件且完成返修
        var transSn = await _transSnRepo.GetFirstAsync(s => s.Sn == input.SN && s.CurLineCode == input.LineCode);
        if (transSn == null)
        {
            return HandleResult.Error(ErrCode.E1402);
        }

        return HandleResult.Ok();
    }
}
